<template>
  <div class="cart-list-item">
    <div class="item-selector">
      <check-button :is-checked="cartItem.checked" @clickItem="clickItem"/>
    </div>

    <div class="item-img">
      <img :src="cartItem.imgURL" alt="">
    </div>

    <div class="item-info">
      <div class="item-title">{{ cartItem.title }}</div>
      <div class="info-bottom">
        <div class="item-price left">¥{{ cartItem.newPrice }}</div>
        <div class="item-count right">x{{ cartItem.count }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import CheckButton from '@/views/cart/childComps/CheckButton'

export default {
  name: "CartListItem",
  components: {
    CheckButton
  },
  props: {
    cartItem: Object
  },
  methods: {
    clickItem() {
      this.cartItem.checked = !this.cartItem.checked
    }
  }
}
</script>

<style scoped>
.cart-list-item {
  width: 100%;
  display: flex;
  padding: 5px;
  border-bottom: 1px solid #ccc;
}

.item-selector {
  width: 15%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.item-img {
  padding: 5px;
}

.item-img img {
  width: 90px;
  height: 90px;
  border-radius: 3px;
  display: block;
  /*图片剪裁不变形*/
  object-fit: cover;
}

.item-info {
  font-size: 16px;
  color: #333;
  padding: 10px 5px;
  position: relative;
  overflow: hidden;
}

.item-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.info-bottom {
  position: absolute;
  bottom: 5px;
  left: 10px;
  right: 10px;
}

.info-bottom .item-price {
  color: orangered;
  font-weight: bolder;
}
</style>
